/*
 * Deck.cpp
 *
 *  Created on: Jul 2, 2012
 *      Author: Admin
 */

#include "Deck.h"

void Deck::setDeck()
{
	deckPlace = 0;
	int counter = 0;
	for (int i=0; i<4; i++){
		for (int j=0; j<13; j++){
			switch (i){
			case 0:
				deck[counter].setSuit("Hearts");
				break;
			case 1:
				deck[counter].setSuit("Diamonds");
				break;
			case 2:
				deck[counter].setSuit("Spades");
				break;
			case 3:
				deck[counter].setSuit("Clubs");
				break;
			}
			switch (j){
			case 0:
				deck[counter].setCardType("Ace");
				break;
			case 1:
				deck[counter].setCardType("2");
				break;
			case 2:
				deck[counter].setCardType("3");
				break;
			case 3:
				deck[counter].setCardType("4");
				break;
			case 4:
				deck[counter].setCardType("5");
				break;
			case 5:
				deck[counter].setCardType("6");
				break;
			case 6:
				deck[counter].setCardType("7");
				break;
			case 7:
				deck[counter].setCardType("8");
				break;
			case 8:
				deck[counter].setCardType("9");
				break;
			case 9:
				deck[counter].setCardType("10");
				break;
			case 10:
				deck[counter].setCardType("Jack");
				break;
			case 11:
				deck[counter].setCardType("Queen");
				break;
			case 12:
				deck[counter].setCardType("King");
				break;
			}
			//			this->deck[0].suit = "";
		}
		counter++;
	}
}

void Deck::shuffle(int numshuffles = 20){
	deckPlace = 0;
	if (numshuffles>=1){
		for (int j=0; j<numshuffles; j++){
			for (int i=0; i<52; i++){
				swap(i,rand()%52);
			}
		}
	}
}

void Deck::swap(int a, int b){
	Card c;
	c=deck[a];
	deck[a]=deck[b];
	deck[b]=c;
}

Deck::Deck() {
	// TODO Auto-generated constructor stub
    void setDeck();
    deckPlace = 0;
    srand(time(NULL));
}

Card Deck::draw(){
	if (deckPlace >= 52){
		shuffle();
	}
	return deck[deckPlace++];
}
